
clear all
set maxvar 120000
set processors 2
set more off

global dir /Volumes/Zihao_SSD2/PatentsView
*** ============================================================================================
*** Table B14. Different values of fixed k=1...10
*** Use different datasets: reg_panel`k'_robust.csv
*** Zihao Li. 11/2024
*** ============================================================================================
* For k = 1
import delimited $dir/regdata/reg_panel1_robust.csv, clear

encode genderdiscrete_09_100_j, gen(genderdiscrete_09_100_j_enc)
encode assignee_id_i, gen(assignee_id_i_enc)
encode assignee_id_j, gen(assignee_id_j_enc)
encode main_cpc_subclass_i, gen(main_cpc_subclass_i_enc)
encode main_cpc_subclass_j, gen(main_cpc_subclass_j_enc)
encode main_cpc_class_i, gen(main_cpc_class_i_enc)
encode main_cpc_class_j, gen(main_cpc_class_j_enc)
encode main_cpc_section_i, gen(main_cpc_section_i_enc)
encode main_cpc_section_j, gen(main_cpc_section_j_enc)
encode assignee_country_i, gen(assignee_country_i_enc)
encode assignee_country_j, gen(assignee_country_j_enc)
drop if patent_year_i==. | main_cpc_section_i=="" | main_cpc_section_j==""

* Col (1)
reghdfe omission allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using "$dir/reg_results/tableb14.doc", replace dec(4) keep(allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* For k = 2...10 (except k=5, which is benchmark)
forval k=2/10 {
	import delimited "$dir/regdata/reg_panel`k'_robust.csv", clear
	
	encode genderdiscrete_09_100_j, gen(genderdiscrete_09_100_j_enc)
	encode assignee_id_i, gen(assignee_id_i_enc)
	encode assignee_id_j, gen(assignee_id_j_enc)
	encode main_cpc_subclass_i, gen(main_cpc_subclass_i_enc)
	encode main_cpc_subclass_j, gen(main_cpc_subclass_j_enc)
	encode main_cpc_class_i, gen(main_cpc_class_i_enc)
	encode main_cpc_class_j, gen(main_cpc_class_j_enc)
	encode main_cpc_section_i, gen(main_cpc_section_i_enc)
	encode main_cpc_section_j, gen(main_cpc_section_j_enc)
	encode assignee_country_i, gen(assignee_country_i_enc)
	encode assignee_country_j, gen(assignee_country_j_enc)
	drop if patent_year_i==. | main_cpc_section_i=="" | main_cpc_section_j==""
	
	reghdfe omission allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
	estadd ysumm
	outreg2 using "$dir/reg_results/tableb14.doc", append dec(4) keep(allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))
}


*** =============================================================================================
*** Table B15. Flexible k.
*** Use reg_panel_flex.csv
*** =============================================================================================
import delimited $dir/regdata/reg_panel_flex.csv, clear

encode genderdiscrete_09_100_j, gen(genderdiscrete_09_100_j_enc)
encode assignee_id_i, gen(assignee_id_i_enc)
encode assignee_id_j, gen(assignee_id_j_enc)
encode main_cpc_subclass_i, gen(main_cpc_subclass_i_enc)
encode main_cpc_subclass_j, gen(main_cpc_subclass_j_enc)
encode main_cpc_class_i, gen(main_cpc_class_i_enc)
encode main_cpc_class_j, gen(main_cpc_class_j_enc)
encode main_cpc_section_i, gen(main_cpc_section_i_enc)
encode main_cpc_section_j, gen(main_cpc_section_j_enc)
encode assignee_country_i, gen(assignee_country_i_enc)
encode assignee_country_j, gen(assignee_country_j_enc)
drop if patent_year_i==. | main_cpc_section_i=="" | main_cpc_section_j==""

* Col (1)
reghdfe omission allfemale_09_100_j sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb15.doc, replace dec(4) keep(allfemale_09_100_j sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (2)
reghdfe omission allfemale_09_100_i sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb15.doc, append dec(4) keep(allfemale_09_100_i sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (3)
reghdfe omission allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb15.doc, append dec(4) keep(allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (4)
reghdfe omission allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag if ((allfemale_09_100_j==1)|(allmale_09_100_j==1)) & ((allfemale_09_100_i==1)|(allmale_09_100_i==1)), absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb15.doc, append dec(4) keep(allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, Homo Gender) addstat(Mean of dependent variable, e(ymean))

* Col (5)
reghdfe omission leadfemale_09_100_j sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb15.doc, append dec(4) keep(leadfemale_09_100_j sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (6)
reghdfe omission leadfemale_09_100_j leadfemale_09_100_i leadfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb15.doc, append dec(4) keep(leadfemale_09_100_j leadfemale_09_100_i leadfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (7)
reghdfe omission allfemale_09_100_j leadfemale_09_100_i allfemale_leadfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb15.doc, append dec(4) keep(allfemale_09_100_j leadfemale_09_100_i allfemale_leadfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (8)
reghdfe omission allfemale_09_100_i leadfemale_09_100_j leadfemale_allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb15.doc, append dec(4) keep(allfemale_09_100_i leadfemale_09_100_j leadfemale_allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))





*** =============================================================================================
*** Table B16. Restrict to KPSS firms before generating the omission index.
*** Use reg_panel_restrict.csv
*** =============================================================================================
import delimited $dir/regdata/reg_panel_restrict.csv, clear

encode genderdiscrete_09_100_j, gen(genderdiscrete_09_100_j_enc)
encode assignee_id_i, gen(assignee_id_i_enc)
encode assignee_id_j, gen(assignee_id_j_enc)
encode main_cpc_subclass_i, gen(main_cpc_subclass_i_enc)
encode main_cpc_subclass_j, gen(main_cpc_subclass_j_enc)
encode main_cpc_class_i, gen(main_cpc_class_i_enc)
encode main_cpc_class_j, gen(main_cpc_class_j_enc)
encode main_cpc_section_i, gen(main_cpc_section_i_enc)
encode main_cpc_section_j, gen(main_cpc_section_j_enc)
encode assignee_country_i, gen(assignee_country_i_enc)
encode assignee_country_j, gen(assignee_country_j_enc)
drop if patent_year_i==. | main_cpc_section_i=="" | main_cpc_section_j==""
	
* Col (1)
reghdfe omission allfemale_09_100_j sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb16.doc, replace dec(4) keep(allfemale_09_100_j sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (2)
reghdfe omission allfemale_09_100_i sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb16.doc, append dec(4) keep(allfemale_09_100_i sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (3)
reghdfe omission allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb16.doc, append dec(4) keep(allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (4)
reghdfe omission allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag if ((allfemale_09_100_j==1)|(allmale_09_100_j==1)) & ((allfemale_09_100_i==1)|(allmale_09_100_i==1)), absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb16.doc, append dec(4) keep(allfemale_09_100_j allfemale_09_100_i allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, Homo Gender) addstat(Mean of dependent variable, e(ymean))

* Col (5)
reghdfe omission leadfemale_09_100_j sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb16.doc, append dec(4) keep(leadfemale_09_100_j sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (6)
reghdfe omission leadfemale_09_100_j leadfemale_09_100_i leadfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb16.doc, append dec(4) keep(leadfemale_09_100_j leadfemale_09_100_i leadfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (7)
reghdfe omission allfemale_09_100_j leadfemale_09_100_i allfemale_leadfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb16.doc, append dec(4) keep(allfemale_09_100_j leadfemale_09_100_i allfemale_leadfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))

* Col (8)
reghdfe omission allfemale_09_100_i leadfemale_09_100_j leadfemale_allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag, absorb(assignee_id_i_enc assignee_id_j_enc patent_year_i main_cpc_section_i_enc main_cpc_section_j_enc) vce(cluster patent_id_i)
estadd ysumm
outreg2 using $dir/reg_results/tableb16.doc, append dec(4) keep(allfemale_09_100_i leadfemale_09_100_j leadfemale_allfemale_09_100_ji sim_score dollar_real_log_j num_citations_i num_inventors_i num_inventors_j avg_experience_i avg_experience_j same_main_cpc same_assignee_country years_lag) addtext(Firm i FE, Yes, Firm j FE, Yes, Year i FE, Yes, Main CPC Section i FE, Yes, Main CPC Section j FE, Yes, Cluster SE, Citing, Sample, All) addstat(Mean of dependent variable, e(ymean))
